package com.servlet;
import com.bean.Student;
import com.dao.StudentDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class addServlet extends HttpServlet{
    public void doPost(HttpServletRequest request,HttpServletResponse response)
            throws ServletException,IOException{
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        Student stu = new Student();
        stu.setId(request.getParameter("id"));
        stu.setName(request.getParameter("name"));
        stu.setSex(request.getParameter("sex"));
        stu.setPhone(request.getParameter("phone"));
        stu.setCno(request.getParameter("cno"));
        stu.setAge(Integer.parseInt(request.getParameter("age")));

        StudentDao.addStudent(stu);
        response.sendRedirect("/showStudents.jsp");
    }
}

